package com.jin.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * Created on 2025/5/14.
 * @Description 响应结果
 * @author Zhongyuan Jin
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)//忽略为null的字段
public class ResponseResult<T> {
    private Integer code; // 状态码，0 表示成功
    private String msg; // 响应消息
    private T data; // 响应数据
    private Long count; // 用于分页的总数
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data,  null);
    }
    public static <T> ResponseResult<T> success(String message, T data) {
        return new ResponseResult<>(ResultCode.SUCCESS.getCode(), message, data,  null);
    }

    public static <T> ResponseResult<T> success(Integer code,  String message,  T data) {
        return new ResponseResult<>(code, message, data,  null);
    }
    public static <T> ResponseResult<T> success( String message,  T data,  Long count) {
        return new ResponseResult<>(ResultCode.SUCCESS.getCode(), message, data,  count);
    }
    public static <T> ResponseResult<T> success(Integer code,  String message,  T data,  Long count) {
        return new ResponseResult<>(code, message, data,  count);
    }
    public static <T> ResponseResult<T> fail(String message,  T data) {
        return new ResponseResult<>(ResultCode.FAIL.getCode(), message, data,  null);
    }
    public static <T> ResponseResult<T> fail(String message) {
        return new ResponseResult<>(ResultCode.FAIL.getCode(), message,null,  null);
    }



}
